var ns, toast, actionsheet, UIAlbumBrowser;
var app = new Vue({
    el: '#app',
    data: {
       list:[],
       keywords:'',
       showsearch:false,
       activeStatus:-1,
       pageindex: 0,
       pagesize: 10,
       is_searching:false,
       can_scroll:false,
       current_item_length: 0,
    },
    methods: {
        //优惠卡券
        get_data:function(){
            var that=this;
            that.is_searching = true;
            that.can_scroll = false;
            var option={};
            option.CouponType=that.activeStatus;
            option.pagesize=that.pagesize;
            option.pageindex=that.pageindex;
            option.action='loadmallcouponcodegrid';
            ns.post(option, function(succeed, data, err) {
                that.is_searching = false;
                if(succeed){
                    if (data.rows.length == that.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.pageindex == 0) {
                        that.list = data.rows;
                    } else {
                        that.list = that.list.concat(data.rows);
                    }
                    that.current_item_length = that.list.length;

                    // that.list=data.rows;
                }else{
                    that.list = [];
                    that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }

            });


        },
        //活动内容
        do_opendetail:function(id){
            var that=this;
            ns.openWin('youhui_cardetail', '卡券详情',{
                id:id
            });
        },
        //添加卡券
        do_addCard:function(){
            var that=this;
            ns.openWin('youhuiCard_add', '新增卡券');
        },
        doClickStatus:function(type){
            var that=this;
            that.activeStatus=type;
            that.showsearch=false;
            that.get_data();
        },
    }
      
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    // toast = new auiToast();
    // actionsheet = new auiActionsheet();
    UIAlbumBrowser = api.require('UIAlbumBrowser');
    ns.init_pull();
    app.get_data();
    api.addEventListener({
        name: 'do_open_saixuan'
    }, function(ret, err) {
        app.showsearch=true;
    });
    
    api.addEventListener({
        name: 'load_card'
    }, function(ret, err) {
        app.get_data();
    });


};
